package com.bobi.tfca.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bobi.tfca.model.entity.GroupEntity;
import com.bobi.tfca.model.entity.GroupMessageEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 群消息持久层
 * @author 李文发
 * @date 2024/4/3
 */
@Mapper
public interface GroupMessageDao extends BaseMapper<GroupMessageEntity> {

    @Select("SELECT COUNT(*) FROM group_message WHERE FIND_IN_SET('{${memberId}}', unread_members)AND group_id = #{groupId}")
    long getUnReadMessageNum(@Param("memberId") Integer memberId, @Param("groupId") Integer groupId);

    @Delete("DELETE FROM message WHERE message_id = #{messageId}")
    void removeMessageByMessageId(Long messageId);

    @Select("SELECT group_id, group_name, owner_id, group_num, group_head FROM bobi_group WHERE group_id = #{groupId}")
    GroupEntity getGroupByGroupId(Integer groupId);
}
